package com.zpark.updater;

import com.zpark.entity.HistoryData;
import com.zpark.entity.SuccessData;

import java.util.HashSet;
import java.util.Set;

public class CityUpdater extends  Updater{

    @Override
    public void update(SuccessData successData, HistoryData historyData, UpdaterChain updaterChain) {
        //1.把登录城市做更新处理

        doUpdate(successData.getCityName(),historyData);
        //2.继续
        updaterChain.doChain(successData, historyData);
    }

    private void doUpdate(String cityName, HistoryData historyData) {
        Set<String> historyCities = historyData.getHistoryCities();
        //1.如果是第一次登录
        if(historyCities==null){
            historyCities = new HashSet<>();
        }

        historyCities.add(cityName);

        historyData.setHistoryCities(historyCities);
    }
}
